import 'package:flutter/material.dart';
import 'package:trip_flutter/widget/searchBarWidget.dart';
import 'package:trip_flutter/widget/searchListWidget.dart';

import '../util/searchTripPosition.dart';

class Searchpage extends StatefulWidget {
  const Searchpage({super.key});

  @override
  State<Searchpage> createState() => _SearchpageState();
}

class _SearchpageState extends State<Searchpage> {
  List<String> supportCitys = [];
  bool hasSearchWord = true;
  void _handelRefresh(String cityName) {
    List<String> result = searchTripPosition.searchAttractionsByCity(cityName);
    setState(() {
      if (result.isEmpty) {
        hasSearchWord = false;
      } else {
        hasSearchWord = true;
      }
      supportCitys = result;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: SearchBarWidget(onSearchChanged: this._handelRefresh),
      ),
      body: Searchlistwidget(cityList: hasSearchWord ? supportCitys : []),
    );
  }

  _content() {
    //得到搜索框返回的数据进行填充
  }
}
